package cn.kongwg.yygh.user.controller;

import cn.kongwg.yygh.common.result.Result;
import cn.kongwg.yygh.model.user.UserInfo;
import cn.kongwg.yygh.user.service.UserInfoService;
import cn.kongwg.yygh.vo.user.UserInfoQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author kongwg
 * @create 2021-04-18 22:03
 */
@RestController
@RequestMapping("admin/user")
public class UserController {

    @Autowired
    private UserInfoService userInfoService;

    //用户列表（条件查询带分页）
    @GetMapping("{page}/{limit}")
    public Result list(@PathVariable Long page,
                       @PathVariable Long limit,
                       UserInfoQueryVo userInfoQueryVo) {
        Page<UserInfo> pageParams = new Page<>(page,limit);
        IPage<UserInfo> pageModle=  userInfoService.selectPage(pageParams,userInfoQueryVo);
        return Result.ok(pageModle);
    }

    //锁定用户
    @GetMapping("lock/{userId}/{status}")
    public Result lock(@PathVariable Long userId,
                       @PathVariable Integer status){
        userInfoService.lock(userId,status);
        return Result.ok();

    }

    @GetMapping("show/{userId}")
    public Result show (@PathVariable Long userId){

        Map<String,Object> map =userInfoService.show(userId);
        return Result.ok(map);
    }

    //审批
    @GetMapping("approval/{userId}/{authStatus}")
    public Result approval(@PathVariable Long userId,
                           @PathVariable Integer authStatus){
        userInfoService.approval(userId,authStatus);
        return Result.ok();
    }

}
